package com.yao.sys.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yao.sys.entity.dto.MenuDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 菜单表
 *
 * @author autoCode
 * @version 1.0.0-SNAPSHOT
 * @date 2020-04-09
 */
@Mapper
@Repository
public interface MenuMapper extends BaseMapper<MenuDto> {

    @Select("select sm.*\n" +
            "from sys_user su\n" +
            "left join sys_user_role_rel surr on su.id = surr.userId\n" +
            "left join sys_role_menu_rel srmr on surr.roleId = srmr.roleId\n" +
            "left join sys_menu sm on srmr.menuId = sm.id\n" +
            "where su.id = ${userId} group by sm.id")
    @InterceptorIgnore(illegalSql="true")
    List<MenuDto> listMenuTreeByUser(@Param("userId") Integer userId);
}